package com.company.goodfuture2021;

public class Main21 {
    public Node reverseList (Node head) {
        // write code here
        if(head == null || head.getNext() == null){
            return head;
        }
        Node dummy = new Node();
        while (head != null){
            Node nextNode = head.getNext();
            head.setNext(dummy.getNext());
            dummy.setNext(head);
            head = nextNode;
        }
        return dummy.getNext();

    }
}

class Node{
    private int data;
    private Node next;

    public int getData() {
        return data;
    }

    public void setData(int data) {
        this.data = data;
    }

    public Node getNext() {
        return next;
    }

    public void setNext(Node next) {
        this.next = next;
    }
}


